<?php
$title = 'Entrenamientos';
$this->headTitle($title);

function getFormattedDate($date) {
    $phpdate = strtotime($date);
    return date('Y-m-d', $phpdate);
}

function getFormattedTime($time) {
    $phpdate = strtotime($time);
    return date('H:i', $phpdate);
}
?>
<div class="content">
    <h1><?php echo $this->escapeHtml($title); ?></h1>
    <center>
        <?php
        if (count($this->paginator) > 0) {
            ?>
            <div style="margin-top: 20px;">
                <table class="table-bordered"  style="width: 70%">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Nombre</th>
                            <th>Creador</th>
                            <th>Inicio</th>
                            <th>Fin</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($this->paginator as $training) : ?>
                            <tr>
                                <td><?php echo $this->escapeHtml($training->training_id); ?></td>
                                <td>
                                    <a href="<?php echo $this->url('training', array('action' => 'edit', 'id' => $training->training_id)); ?>"><?php echo $this->escapeHtml($training->training_name); ?></a>
                                </td>
                                <td><?php echo $this->escapeHtml($training->name . ' ' . $training->lastname); ?></td>
                                <td><?php echo $this->escapeHtml(getFormattedDate($training->start_date) . ' ' . getFormattedTime($training->start_time)); ?></td>
                                <td><?php echo $this->escapeHtml(getFormattedDate($training->end_date) . ' ' . getFormattedTime($training->end_time)); ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>	
            <?php
        }else {
            echo "No existen entrenamientos creados.";
        }
        ?>
    </center>
    <?php
    echo $this->paginationControl($paginator, 'Sliding', 'training-paginator');
    ?>
</div>

